package com.tengju.settlement.domain.model.depository;

import com.tengju.settlement.domain.model.account.UserIdCode;
import lombok.AllArgsConstructor;
import lombok.Value;

import java.util.Optional;

/**
 * @author: 大木
 * @date: 2021/12/7 1:38 上午
 */
@Value
@AllArgsConstructor
public class AbmDepositoryAggregatedInfo {

    UserIdCode idCode;

    /**
     * 开户信息
     */
    DepositoryAccount depositoryAccount;

    /**
     * 默认的有效银行卡: 绑卡成功的银行卡
     */
    DepositoryBankCard bankCard;

    License legalLicense;

    public boolean compareAccountLicense(License license) {
        return depositoryAccount.compareAccountLicense(license);
    }

    public boolean compareLegalAccountLicense(License license) {
        if (license == null) {
            return false;
        }
        return this.legalLicense.getLicenseType() == license.getLicenseType()
                && this.legalLicense.getLicenseNumber().equals(license.getLicenseNumber());
    }

    public boolean isValid() {
        return depositoryAccount != null && bankCard != null;
    }

    public String cardNo() {
        return Optional.ofNullable(bankCard).map(DepositoryBankCard::getCardNo).orElse("");
    }

    public String bankName() {
        return Optional.ofNullable(bankCard).map(DepositoryBankCard::getBankName).orElse("");
    }

    public String superBankNo() {
        return Optional.ofNullable(bankCard).map(DepositoryBankCard::getSuperBankNo).orElse("");
    }

    public String mobileForBank() {
        return Optional.ofNullable(bankCard).map(DepositoryBankCard::getExtra)
                .map(BankCardExtra::getReservedMobile).orElse("");
    }

    public BankCardType cardType() {
        return Optional.ofNullable(bankCard).map(DepositoryBankCard::getCardType).orElse(null);
    }

}
